package com.example.work4.view

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.widget.LinearLayout

open class BottomDialog(context: Context, var layoutId: Int) : Dialog(context, layoutId) {

    var view:View?=null

    override fun onCreate(savedInstanceState: Bundle?) {
        window?.requestFeature(Window.FEATURE_NO_TITLE)
        super.onCreate(savedInstanceState)
        view = View.inflate(context, layoutId, LinearLayout(getContext())); //给个默认的ViewGroup,解决最外层布局的margin问题
        view?.let { setContentView(it) }
        window?.navigationBarColor = Color.WHITE
        init()

    }

    open fun init(){}

    override fun onStart() {
        super.onStart()
        getWindow()?.setBackgroundDrawableResource(android.R.color.transparent); //去除自带的背景

        getWindow()?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); //宽度占满
        getWindow()?.setGravity(Gravity.BOTTOM);
    }
}